home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14985 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: rz.uni-karlsruhe.de!not-for-mail
  2. From: frick@i44sg1.informatik.uni-karlsruhe.de (Arne K. Frick)
  3. Newsgroups: comp.lang.tcl,comp.lang.c,comp.os.linux.development.system
  4. Subject: How do I get a (FILE *) from file descriptor?
  5. Date: 16 Apr 1996 17:27:18 +0200
  6. Organization: Universitaet Karlsruhe, FRG
  7. Sender: frick@i44sg1.info.uni-karlsruhe.de
  8. Message-ID: <yvdohosur3f.fsf@i44sg1.info.uni-karlsruhe.de>
  9. NNTP-Posting-Host: i44sg1.info.uni-karlsruhe.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=iso-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. CC: drepper
  14. X-Newsreader: Gnus v5.1
  15.  
  16. Background: A Tcl extension I use depends on using the (FILE *) form for
  17. describing its file handles.  However, in Tcl-7.5b3 J. Ousterhout dropped
  18. support for the UNIX-specific command 'Tcl_GetOpenFile' which would take a
  19. Tcl handle and return the associated (FILE *).  Now, all there is is a set
  20. of functions ultimately giving me an (int) as a file descriptor.
  21.  
  22. I came up with the following piece of code that supposedly would use
  23. 'fdopen' to do the task.  This seems to work fine for read-access, but when
  24. opening the file for writing 'fdopen' dumps core.
  25.  
  26.     chan = Tcl_GetChannel(interp, argv[3], &mode);
  27.     if (chan == (Tcl_Channel) NULL) {
  28.       Tcl_AppendResult(interp, "GdWriteCmd: Failure to get channel id", argv[3],
  29.             (char *) NULL);
  30.       return TCL_ERROR;
  31.     }
  32.     tf=Tcl_GetChannelFile(chan,TCL_WRITABLE);
  33.     if (tf==(Tcl_File) NULL) {
  34.       Tcl_AppendResult(interp, "GdWriteCmd: Failure to get file handle",
  35.                (char *) NULL);
  36.       return TCL_ERROR;
  37.     }
  38.     fd = (int) Tcl_GetFileInfo(tf, NULL);
  39.     curStatus = fcntl(fd, F_GETFL);
  40.     fprintf(stderr,"current status: %d\n",curStatus);
  41.     if (curStatus<0) {
  42.       Tcl_AppendResult(interp,"Gd_WriteCmd: file status error\n", (char *) NULL);
  43.     }
  44.  
  45.     f = fdopen(fd,"w+");
  46.     if (f == (FILE *) NULL) {
  47.       Tcl_AppendResult(interp, "GdWriteCmd: Failure to get file descriptor",
  48.                (char *) NULL);
  49.       return TCL_ERROR;
  50.     }
  51.  
  52. Obviously, the Linux libc-5.2.8 should not core dump in 'fdopen' in the
  53. first place.  This is a bug.  The more interesting question, however, is
  54. whether my approach is feasible at all, or whether there is a better
  55. strategy other than to rewrite the existing library I'm interfacing to.
  56.  
  57. Here's the configuration in question again:
  58.  
  59.     Linux Kernel 1.3.80
  60.     libc-5.2.8
  61.     Tcl-7.5b3/Tk-4.1b3
  62.  
  63. I am trying to interface the gd1.2 library for GIF file
  64. creation/manipulation, just in case anyone asks.  It uses (FILE *)'s all
  65. over the place.
  66.  
  67.  
  68. Any advice/help is certainly welcome.
  69.  
  70.  
  71.  
  72. -- 
  73. Arne Frick               |Tel.:  0721/608-4763    
  74. Universitaet Karlsruhe   |Fax:   0721/691462
  75. Vincenz-Priessnitz-Str. 3|EMail: Arne.Frick@informatik.uni-karlsruhe.de
  76. 76128 Karlsruhe          |URL http://i44www.info.uni-karlsruhe.de/~frick
  77.